#!/usr/bin/env python
# -*- coding:utf-8 -*-

import sys
reload(sys)
sys.setdefaultencoding('utf8')

import logging, __builtin__
from utils.memcacheStore import MemcacheStore

# for debug
log = logging.getLogger()
__builtin__.__dict__['default_log'] = log

import web
import jinja2

web.config.debug = False

jjenv = jinja2.Environment(loader=jinja2.FileSystemLoader('views'),extensions=["jinja2.ext.do",], autoescape=True)

from controllers import *

urls = (
    "/", "Statistics", # get 整体统计
    '/(\d+)', 'Statistics', # get 分公司统计
    '/users', 'Users', # post 新增公司
    '/companys', 'Companys', # post 新增公司
    '/company/(\d+)/(finished_cases|unfinished_cases|cases)', 'CompanyCases', # get 案件列表 post创建案件
    '/company/(\d+)/case/(\d+)', 'CompanyCase', # get 案件详情 post 案件操作
    '/company/(\d+)/(finished_cases|unfinished_cases)/excel', 'CompanyCasesExcel', # get 下载excel
    '/create/user', 'CreateUser',
    '/create/company', 'CreateCompany',
    '/create/company/(\d+)/case', 'CreateCompanyCase',
    '/help', 'Help',
    '/login', 'Login', # get|post 登陆
    '/logout', 'Logout',
    '/contacts', 'Contacts', # get 列表 | post 新增
    '/create/contact', 'CreateContact',
    '/delete/contact/(\d+)', 'DeleteContact', # post 删除
)

app = web.application(urls,globals())

session = web.session.Session(app, MemcacheStore(), initializer = {'username' : '','login' : False, 'user' : None})

def session_hook():
    web.ctx.session = session

app.add_processor(web.loadhook(session_hook))

if __name__ == "__main__":
    app.run()
else:
    application = app.wsgifunc()
